package com.evan.uyclub.AppStore;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.evan.uyclub.R;
import com.squareup.picasso.Picasso;

import java.util.List;

public class ListnAdapter extends ArrayAdapter<ListReturn> {
    private int resourceId;
    private Context mContext;
    private ListReturn list;

    public ListnAdapter(Context context, int textId, List<ListReturn> object) {
        super(context, textId, object);
        resourceId = textId;
        mContext = context;
    }

    @SuppressLint("CutPasteId")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ListReturn listReturn = getItem(position);
        list = listReturn;
        View view;
        ViewHolser viewHolser;

        if (convertView == null) {
            view = LayoutInflater.from(getContext()).inflate(resourceId, parent, false);
            viewHolser = new ViewHolser();
            viewHolser.item_icon = (ImageView) view.findViewById(R.id.item_icon);
            viewHolser.item_name = (TextView) view.findViewById(R.id.item_name);
            viewHolser.item_referral = (TextView) view.findViewById(R.id.item_referral);
            viewHolser.item_download_url = (TextView) view.findViewById(R.id.item_download_url);
            view.setTag(viewHolser);
        } else {
            view = convertView;
            viewHolser = (ViewHolser) view.getTag();
        }

        // 设置视图内容
        Picasso.with(mContext).load("https://image.woozooo.com/image/ico/" + listReturn.getIconApp()).noPlaceholder().error(R.mipmap.ic_load).into(viewHolser.item_icon);
        viewHolser.item_name.setText(listReturn.getNameApp());
        viewHolser.item_referral.setText(listReturn.getReferralApp());
        viewHolser.item_download_url.setText(listReturn.getDownloadUrl());

        return view;
    }

    static class ViewHolser {
        ImageView item_icon;
        TextView item_name, item_referral, item_download_url;
    }

}